package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;


import java.util.Map;

import static com.heima.common.constants.WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC;

/**
 * @author JianKang
 * @create 2023-10-28 14:42
 */
@Component
@Slf4j
public class ArticleIsDownListener {

    @Autowired
    ApArticleConfigService apArticleConfigService;


    @KafkaListener(topics = WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessage(String message) {
        if (StringUtils.isNoneBlank(message)) {
            Map map = JSON.parseObject(message, Map.class);
            apArticleConfigService.updateByMap(map);
        }
    }
}
